package cc.vv.baselibrary.util

import android.content.Context
import android.graphics.Typeface
import android.widget.ImageView
import android.widget.TextView
import cc.vv.baselibrary.R
import cc.vv.lkimagecomponent2.LKImage

/**
 * 基础类型扩展函数类
 * Created by sun.li on 2018/7/11.
 * @author sun.li
 */
fun String.toast() {
    try {
        LKToastUtil.showToastShort(this)
    } catch (e: Exception) {
    }
}

fun ImageView.loadUrl(url: String?) {
    if(null==url){
        return
    }
    try {
        LKImage.load().placeHolder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).load(url).into(this)
    } catch (e: Exception) {
    }
}

fun ImageView.loadUrl(url: String?, resId: Int) {
    if(null==url){
        return
    }
    try {
        LKImage.load().placeHolder(resId).error(resId).load(url).into(this)
    } catch (e: Exception) {
    }
}

fun ImageView.setResources(resources: Int) {
    try {
        this.setImageResource(resources)
    } catch (e: Exception) {
    }
}

/**
 * 设置textview字体  健康报告圆形进度条数字使用
 */
fun TextView.BebasNeueBoldType(context: Context) {
    this.typeface = Typeface.createFromAsset(context.assets, "BebasNeueBold.ttf")
}